package org.traffometer.packet.location;

/**
 * Implements a representation for a longitude coordinate. 
 *
 * @author Aaron A. Kagawa
 * @version $Id$
 */
public class Longitude extends PhysicalCoordinate {
  
  /**
   * Constructs a Longitude with the specified degrees, minutes, seconds, and direction.
   * @param degrees The Longitude degrees. This value must be positive.
   * @param minutes The Longitude minutes. This value must be positive.
   * @param seconds The Longitude seconds. This value must be positive.
   * @param hemisphere The Longitude's hemisphere either Hemisphere.EAST or Hemisphere.WEST.
   * @throws LocationException If an invalid parameters is passed to this constructor. 
   */
  public Longitude(int degrees, int minutes, double seconds, Hemisphere hemisphere) 
    throws LocationException {
    super(degrees, minutes, seconds, hemisphere);
    if (hemisphere != Hemisphere.East && hemisphere != Hemisphere.West) {
      throw new LocationException("Invalid hemisphere. Must be either East or West");
    }
  }
  
  /**
   * Constructs a Longitude based on its sexagesimal notation.
   * @param coordinateInSexagesimal The physical coordinate in sexagesimal units.
   */
  public Longitude(double coordinateInSexagesimal) {
    super(coordinateInSexagesimal);
  }
    
  /**
   * Constructs a copy of the specified Longitude object.
   * @param longitude The Longitude object to be copied. 
   */
  public Longitude(Longitude longitude) {
    this(longitude.toSexagesimal());
  }
  
  /**
   * Returns the hemisphere that this Latitude object is associated with. 
   * @return the hemisphere, either Hemisphere.EAST or Hemisphere.WEST.
   */
  public Hemisphere getHemisphere() {
    if (super.coordinateInSexagesimal > 0) {
      return Hemisphere.East;
    }
    else {
      return Hemisphere.West;
    }
  }
  
  /**
   *  Returns a string representation of this Longitude object.
   *  @return A string representation of this Longitude object.
   */
  public String toString() {
    if (this.getHemisphere() == Hemisphere.West) {
      return getDegrees() + " " + this.getMinutes() + "'" + this.getSeconds() + "'' W";
    }
    else {
      return getDegrees() + " " + this.getMinutes() + "'" + this.getSeconds() + "'' E";
    }
  }
  
}